define(function(require, exports, module) {
    var ALL = require("../../common/all"),
        CONFIG = ALL.CONFIG,
        METHOD = ALL.METHOD,
        Dialog = ALL.Dialog,
        Init = ALL.Init;

    var _Dialog = new Dialog({
        title : "提示",
        content : "<p></p>",
        text4Btn: ["确定"],
        class4Btn: [""]
    });

    var _vm = Init.initVue({
        data : {
            check: {},
            user_id : '',
            res : {
                type : 1,
                col_id : '',
                file : '',
                trade_no : '',
                user_name : ''
            }
        },
        methods: {
            submit : function() {
                var obj = {
                    type: _vm.res.type,
                    col_id : _vm.res.col_id,
                    user_id : _vm.user_id
                };

                this.check.$valid();
                flag = this.check.flag;

                if (!flag) { return; }

                // new FormData
                var fd = new FormData();
                fd.append("data", JSON.stringify(obj));
                fd.append("file", _vm.res.file);

                METHOD.loading.show();
                METHOD.ajax("purchaseblist/create",fd,{type : 'post',upload : true}).done(function(json){
                    METHOD.loading.hide();
                    if (_vm.res.type == 2) {
                        _Dialog.changeCfg({content : "<p>" + json.msg + "</p>"});
                        _Dialog.showUI(function() {
                            _vm.checkAgain();
                            this.hideUI();
                        });
                    } else {
                        _vm.checkAgain();
                    }
                }).fail(function(){
                    METHOD.loading.hide();
                });
            },
            checkAgain : function() {
                METHOD.alert("操作成功").done(function(){
                    window.location.href = "../control/purchase.html";
                });
            },
            uploadFile : function(e, name) {
                var files = e.target.files,
                    file = files[0];

                if (files.length == 0 ) return;

                if (!/^.+\.(xls)|(xlsx)|(csv)$/i.test(file.name)) {
                    METHOD.alert("请上传正确的excel格式文件")
                } else {
                    _vm.res[name] = file;
                }
            },
            getInfoCallback : function(o) {
                if (o) {
                    this.user_id = o.id;
                    this.res.user_name = o.name;
                } else {
                    this.user_id = "";
                    this.res.user_name = "";
                }
            }
        }
    });

});

